﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Web;

namespace XRERP.Models
{
    /// <summary>
    /// JsonRetrun Json返回值
    /// </summary>
    public class JR//: DynamicObject
    {

       // private Dictionary<String, object> data = new Dictionary<string, object>();

        /// <summary>
        /// Json返回值
        /// </summary>
        public JR()
        {

        }

        /// <summary>
        /// Json返回值
        /// </summary>
        /// <param name="code">返回代码</param>
        /// <param name="msg">返回信息</param>
        public JR(int code, String msg)
        {
            this.code = code;
            this.msg = msg;
        }

         /// <summary>
         /// Json返回值
         /// </summary>
         /// <param name="code">返回代码</param>
         /// <param name="msg">返回信息</param>
         /// <param name="isError">是否有错误</param>
        public JR(int code, String msg,bool isError)
        {
            this.code = code;
            this.msg = msg;
            this.isError = isError;
        }

        public int code { get; set;  }
        public String msg { get; set; }
        public bool isError { get; set; }
        public bool success { get; set; }
        public String message { get; set; }


        /*  public void SetMember<T>(T obj)
         {
             object ob = new object();
             Type o= obj.GetType();
             foreach (MemberInfo info in o.GetMembers())
             {
                 PropertyInfo pi= o.GetProperty(info.Name);
                 if (null != pi)
                 {
                     //System.Diagnostics.Debug.WriteLine(pi.GetValue(obj, null));
                     data.Add(info.Name, pi.GetValue(obj, null));
                 }
             }

         }

        public override bool TryGetMember(GetMemberBinder binder, out object result)
         {
             bool ret = true;

             if(data.ContainsKey(binder.Name))
             {
                 ret = data.TryGetValue(binder.Name,out result);
             }
             else 
             {
                 switch(binder.Name)
                 {
                     case "code":
                         result = this.code;
                         break;
                     case "msg":
                         result = this.msg;
                         break;
                     case "isError":
                         result = this.isError;
                         break;
                     default:
                         result = null;
                         ret = false;
                         break;
                 }
             }

             return ret;
         }

         /// <summary>
         /// 获取所有属性名称
         /// </summary>
         /// <returns></returns>
         public override IEnumerable<string> GetDynamicMemberNames()
         {
             return base.GetDynamicMemberNames();
         }

         public override bool TrySetMember(SetMemberBinder binder, object value)
         {

             return base.TrySetMember(binder, value);
         }*/
    }
}